<#assign base=request.contextPath />
<#import "/tags/select.ftl" as k />
<!DOCTYPE html>
<html>
<head>
  <base href="${base}">	
  <meta charset="utf-8">
  <title>列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${base}/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${base}/layuiadmin/layui/css/formSelects.css" media="all">
  <link rel="stylesheet" href="${base}/css/my.css" media="all">
</head>

<body>
  	<div class="layui-form" lay-filter="LAY-form-list" style="padding: 20px 30px 0 0;">
  		<input type="hidden" name="oid" value="${(examine.oid)!}">
  		<div class="layui-form-item">
			<label class="layui-form-label required">课程类型</label>
			<div class="layui-input-block">
				<select name="courseType.dicId" lay-verify="required" lay-search>
	    			<option value="">---请选择---</option>
	      			<@dicts itemName="课程类型">
	      				<#list items as item>
	      					<#if ((examine.courseType.dicId)!0) == item.dicId>
	      						<option value="${item.dicId}" selected>${item.itemValue}</option>
	      					<#else>
	      						<option value="${item.dicId}">${item.itemValue}</option>
	      					</#if>  				
	      				</#list>
	      			</@dicts>
      			</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">考试时间</label>
			<div class="layui-input-block">
				<input type="text" name="examDate" value="${(examine.examDate)!}" lay-verify="required" class="layui-input" placeholder="考试时间" />
			</div>
		</div>
  		<div class="layui-form-item flex1">
			<label class="layui-form-label required">考试名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" value="${(examine.name)!}" class="layui-input" placeholder="考试名称" />
			</div>
		</div>
		<div class="layui-form-item flex1">
			<label class="layui-form-label required">主考教师</label>
			<div class="layui-input-block">
				<select xm-select="select1" id="teacherIds" xm-select-search=""></select>
			</div>
			<input type="hidden" name="teacherIds" value="${(examine.teacherIds)!}">
			<input type="hidden" name="teacherNames" value="${(examine.teacherNames)!}">
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">适用年级</label>
			<div class="layui-input-block">
				<select name="dept.depId" lay-verify="required" lay-search>
	    			<option value="">---请选择---</option>
	      			<@combo model="Department" where="orgType=1">
	      				<#list items as item>
	      					<#if ((examine.dept.depId)!0) == item.depId>
	      						<option value="${item.depId}" selected>${item.depName}</option>
	      					<#else>
	      						<option value="${item.depId}">${item.depName}</option>
	      					</#if>  				
	      				</#list>
	      			</@combo>
      			</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">考试状态</label>
			<div class="layui-input-block">
				<@k.select id="status" datas=[[0,'末开始'],[1,'进行中'],[2,'已结束']] value='${(examine.status)!}'/>
			</div>
		</div>
		<div class="layui-form-item flex1">
			<label class="layui-form-label">考试说明</label>
			<div class="layui-input-block">
				<textarea name="note" class="layui-textarea" placeholder="考试说明">${(examine.note)!}</textarea>
			</div>
		</div>
	    <div class="layui-form-item layui-hide">
	      	<input type="button" lay-submit lay-filter="LAY-form-submit" id="LAY-form-submit" value="确认添加">
	      	<input type="button" lay-submit lay-filter="LAY-form-edit" id="LAY-form-edit" value="确认编辑">
	    </div>
  	</div>

  <script src="${base}/js/lib/jquery-1.11.3.min.js"></script>
  <script src="${base}/js/commons.js"></script>
  <script src="${base}/layuiadmin/layui/layui.js"></script>
  <script>
  	layui.config({
    	base: '${base}/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index'
  	}).use(['index', 'form', 'laydate', 'formSelects'], function(){
    	var form = layui.form;
    	var formSelects = layui.formSelects;
	
    	// 获得教师
		$$.ajax({
			async: false,
			url: "${base}/exam/examine/teachers",
			success: function(json) {
				$('#teacherIds').empty();
				for(var i=0; i<json.length; i++) {					
					$('#teacherIds').append('<option id = "teacher'+json[i].userId+'" value="'+json[i].userId+'">' + json[i].fullname + '</option>');
				}
				form.render('select');
			}
		});
    	
		//多选教师
		formSelects.render('select1', {
			<#if examine?? && examine.teacherIds??>
			init: '${examine.teacherIds}'.split(','),
			</#if>
			skin: "danger",
			height: "auto",
			radio: false,
			direction: "auto"
			//max:3
		});
		
    	
    	//监听提交
    	form.on('submit(LAY-form-submit)', function(data) {
      		var index = parent.layer.getFrameIndex(window.name); 
      		// 获得多选框的值
      		var params = data.field;
      		params.teacherIds = formSelects.value('select1', 'valStr');;
      		params.teacherNames = formSelects.value('select1', 'nameStr');
      		
      		$$.ajax({
      			url: '${base}/exam/examine/save',
      			data: params,
      			success: function(json) {
      				parent.layui.table.reload('LAY-table');
      	      		parent.layer.close(index);
      			}
      		});
    	});
  	})
  </script>
</body>
</html>